#ifdef __PME_SUPPORT__

#include "MMI_Include.h"

#include "mrporting.h"
#include "pme_i.h"
#include "pme_def.h"
#include "pme.h"

#ifdef __IS_10A__
#include "ProfilesSrvGprot.h"
#include "mmi_rp_app_sms_def.h"
#else
#include "FileManagerGprot.h"
#include "SettingProfileEnum.h"
#include "mmidsmdef.h"
#include "MessagesResourceData.h"
#endif

#include "resource_audio.h"
#include "IdleAppDef.h"


/*****************************************************************************
 * CONST & STRUCT
 * 
 *****************************************************************************/

#define PME_MAIN_LOAD_TIME 2000//ms
#define PME_MAIN_SCREEN_ITEM_MAX 5
#define PME_SUB_SCREEN_ITEM_MAX 10
#define PME_REPLY_TEXT_MAX_LEN 512//字符

typedef struct
{
	//uint16 *title;	
	uint8 mainHili;//主菜单hili
	uint8 subHili;//list 子菜单HILI
	uint8 opHili;//option菜单hili
	uint8 setHili;//setting菜单hili
	uint8 setSubHili;//setting 菜单hili
	uint8 opType;//
	
	int8 stype;
	int8 otype;
	int8 canReply;
	uint8 opNum;
	int32 vonder;

	/*for reply msg*/
	char *edtBuf;
	
}pme_main_screen_st;

static pme_main_screen_st s_pme_list_screen = {0};
U16 pme_list_icons_image_list[PME_SUB_SCREEN_ITEM_MAX + 2] = {0};

extern U8 hintData[MAX_SUB_MENUS][MAX_SUB_MENU_HINT_SIZE];
extern PU8 hintDataPtrs[MAX_SUB_MENUS];
extern U8 subMenuData[MAX_SUB_MENUS][MAX_SUB_MENU_SIZE];
extern PU8 subMenuDataPtrs[MAX_SUB_MENUS];
extern wgui_inline_item wgui_inline_items[];

extern const U16 gIndexIconsImageList[];
extern pBOOL IsBackHistory;
static void pme_main_screen_show(int32 refresh);
extern void ShowCategory74Screen_ext(U8 * title,U16 title_icon,U16 left_softkey,U16 left_softkey_icon,U16 right_softkey,U16 right_softkey_icon,U8* buffer,S32 buffer_size,U8* history_buffer);

/*****************************************************************************
 * SUPPORT FUNCTION
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_list_get_cust_str
 * DESCRIPTION: 
 * PARAMETERS: 
 * RETURNS: void
 *****************************************************************************/
char* pme_list_get_cust_str(pme_list_str_en id)
{
	switch(id){
		case DAPLS_NAV_PREV:
			return (char*)get_string(STR_PME_NAVI_PREV);
		case DAPLS_NAV_NEXT:
			return (char*)get_string(STR_PME_NAVI_NEXT);
		case DAPLS_NOTIFY_MAIL:
			return (char*)get_string(STR_PME_NOTIFY_MAIL);
		case DAPLS_NOTIFY_IM:
			return (char*)get_string(STR_PME_NOTIFY_IM);	
		default:
			break;	
	}
	
	return NULL;
}

/*****************************************************************************
 * FUNCTION: pme_list_storage_space_is_lower
 * DESCRIPTION: 
 * PARAMETERS: 
 * RETURNS: void
 *****************************************************************************/
static void pme_no_space_error_exit(void)
{
	
}

static int32 pme_list_storage_space_check(void)
{	
	U8 *gui_buffer;
	U8* str = (U8*)get_string(STR_PME_STORAGE_LOWER);
	
	if(pme_port_storage_space_is_lower(pme_get_cur_storage(), PME_STORAGE_FREE_SPACE_MIN)){
		//mmi_popup_display((WCHAR*)text, event_id, NULL);
		/*DisplayPopup((PU8) GetString(STR_PME_STORAGE_LOWER), 
							IMG_GLOBAL_WARNING, 
							1, 
							ST_NOTIFYDURATION, 
							WARNING_TONE 
							);
		*/
		//DeleteScreenIfPresent(SCR_PME_MAIN_SCREEN);
		EntryNewScreen(SCR_PME_ENTRY_LOGO, pme_no_space_error_exit, NULL, NULL);
		ShowCategory74Screen(STR_GLOBAL_ERROR, 0,STR_GLOBAL_OK, IMG_GLOBAL_OK,NULL, NULL,
									(U8*) str, mmi_ucs2strlen((S8*)str),0 );  
		SetLeftSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);
		return TRUE;
	}

	return FALSE;
}


/*****************************************************************************
 * MSG REPLY
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_msg_replyscreen_free_res
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_replyscreen_free_res(void)
{
	pme_ui_trace((MOD_MMI,"pme_msg_replyscreen_free_res()"));
	if(s_pme_list_screen.edtBuf){
		pme_port_mem_free((void**)&s_pme_list_screen.edtBuf);
		s_pme_list_screen.edtBuf = NULL;
	}
}

/*****************************************************************************
 * FUNCTION: pme_msg_replyscreen_lsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_replyscreen_lsk(void)
{
	int32 ret;
	char* destBuf = s_pme_list_screen.edtBuf + (PME_REPLY_TEXT_MAX_LEN + 1)*2;
	pme_ui_trace((MOD_MMI,"pme_msg_replyscreen_lsk()"));
 
	pme_port_ucs2_to_utf8_string((uint8 *)destBuf, (PME_REPLY_TEXT_MAX_LEN + 1)*4, (uint8 *)s_pme_list_screen.edtBuf);
 	ret = pme_list_msg_send_context(destBuf, strlen(destBuf));
	if(ret == MR_FAILED){
	    DisplayPopup((PU8) GetString(STR_GLOBAL_FAILED_TO_SEND), 
	                        IMG_GLOBAL_FAIL, 
	                        1, 
	                        ST_NOTIFYDURATION, 
	                        0 
	                        );
	}else if(ret == MR_WAITING){
		DisplayPopup((PU8) GetString(STR_GLOBAL_BUSY_TRY_LATER), 
	                        IMG_GLOBAL_FAIL, 
	                        1, 
	                        ST_NOTIFYDURATION, 
	                        0 
	                        );
	}else{
		GoBackHistory();
	    DisplayPopup((PU8) GetString(STR_GLOBAL_SENDING), 
	                        IMG_GLOBAL_OK, 
	                        1, 
	                        ST_NOTIFYDURATION, 
	                        0 
	                        );
		//mmi_popup_display((WCHAR*)text, event_id, NULL);
		pme_msg_replyscreen_free_res();
	}
}

/*****************************************************************************
 * FUNCTION: pme_msg_replyscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_replyscreen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_msg_replyscreen_rsk()"));
	GoBackHistory();
	pme_msg_replyscreen_free_res();
}

/*****************************************************************************
 * FUNCTION: pme_msg_replyscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_replyscreen_exit(void)
{
     //screen out.
	 pme_ui_trace((MOD_MMI,"pme_msg_replyscreen_exit()"));
}

/*****************************************************************************
 * FUNCTION: pme_msg_replyscreen_del
 * DESCRIPTION: screen been  deleted
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static U8 pme_msg_replyscreen_del(void *data)
{
	pme_ui_trace((MOD_MMI,"pme_msg_replyscreen_del(), %d", data));
	pme_msg_replyscreen_free_res();
	return MMI_FALSE;
}

/*****************************************************************************
 * FUNCTION: pme_msg_replyscreen_entry
 * DESCRIPTION: show text screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_msg_replyscreen_entry(void)
{
	U8* gui_buffer = NULL;
 	pme_ui_trace((MOD_MMI, "pme_msg_replyscreen_entry()")); 
	
	EntryNewScreen(SCR_PME_POP_SNDMSG, pme_msg_replyscreen_exit, pme_msg_replyscreen_entry, NULL);	 
	SetDelScrnIDCallbackHandler(SCR_PME_POP_SNDMSG, pme_msg_replyscreen_del);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_POP_SNDMSG);
	if(!gui_buffer){
		s_pme_list_screen.edtBuf = (char*)pme_port_mem_malloc((PME_REPLY_TEXT_MAX_LEN + 1)*6);
		if(!s_pme_list_screen.edtBuf){
			GoBackHistory();
			return;
		}
		memset(s_pme_list_screen.edtBuf, 0, (PME_REPLY_TEXT_MAX_LEN + 1)*6);
	}

	ShowCategory5Screen_ext(0, 0,
                                 STR_GLOBAL_OK, 0,
                                 STR_GLOBAL_BACK, 0,
                                 IMM_INPUT_TYPE_SENTENCE,
                                 (U8*)s_pme_list_screen.edtBuf, (PME_REPLY_TEXT_MAX_LEN + 1), 
                                 gui_buffer,0,NULL
                                 );
	SetLeftSoftkeyFunction(pme_msg_replyscreen_lsk, KEY_EVENT_UP);
	SetCategory5RightSoftkeyFunction(pme_msg_replyscreen_rsk , KEY_EVENT_UP);
}

/*****************************************************************************
 * MSG OPTION
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_msg_optionscreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_optionscreen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_msg_optionscreen_hilite(), hilight: %d", hilight));
	s_pme_list_screen.opHili = hilight;
}

/*****************************************************************************
 * FUNCTION: pme_msg_optionscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_optionscreen_exit(void)
{
     //screen out.
	 pme_ui_trace((MOD_MMI,"pme_msg_optionscreen_exit()"));
}

/*****************************************************************************
 * FUNCTION: pme_msg_optionscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_optionscreen_lsk(void)
{
	int32 nNumofItems = 0;

	if(s_pme_list_screen.canReply){//直接回复
		if(nNumofItems == s_pme_list_screen.opHili){
			pme_list_msg_option(PME_MSG_OPTION_REPLY);
		}
		
		nNumofItems++;
	}

	if(s_pme_list_screen.vonder > 0){//登录app
		switch(s_pme_list_screen.stype){
			case PME_STYPE_IM://STR_PME_START_APP
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_IM);
				}
				break;
			case PME_STYPE_EMAIL://STR_PME_START_EMAIL
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_EMAIL);
				}
				break;
			default://STR_PME_START_APP
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_APPENTRY);
				}
				break;
		}
		
		nNumofItems++;
	}
	
	if(s_pme_list_screen.otype > PME_OTYPE_NONE){//启动附加功能
		switch(s_pme_list_screen.otype){
			case PME_OTYPE_WAP:
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_WAP);
				}
				break;
			case PME_OTYPE_CALL:
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_CALL);
				}
				break;
			case PME_OTYPE_SMS:
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_SMS);
				}
				break;
			case PME_OTYPE_APPENTRY:
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_APPENTRY);
				}
				break;
			case PME_OTYPE_APPLOAD:
				if(nNumofItems == s_pme_list_screen.opHili){
					pme_list_msg_option(PME_MSG_OPTION_APPLOAD);
				}
				break;
		}
		
		nNumofItems++;
	}
	
}

/*****************************************************************************
 * FUNCTION: pme_msg_optionscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_optionscreen_rsk(void)
{
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: pme_msg_optionscreen_entry
 * DESCRIPTION: start app option
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_optionscreen_entry(void)
{
	U8 *guiBuffer;
	U8 *menuStringList[10] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_msg_optionscreen_entry()"));
	
	EntryNewScreen(SCR_PME_SUB_OPTION, pme_msg_optionscreen_exit, pme_msg_optionscreen_entry, NULL);
	RegisterHighlightHandler(pme_msg_optionscreen_hilite);
	guiBuffer = GetCurrGuiBuffer(SCR_PME_SUB_OPTION);
	if(!guiBuffer){
		s_pme_list_screen.opHili = 0;
	}

	if(s_pme_list_screen.canReply){//直接回复
		menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_REPLY_MSG);
	}

	if(s_pme_list_screen.vonder > 0){//登录app
		switch(s_pme_list_screen.stype){
			case PME_STYPE_IM://STR_PME_START_APP
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_START_APP);
				break;
			case PME_STYPE_EMAIL://STR_PME_START_EMAIL
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_START_EMAIL);
				break;
			default://STR_PME_START_APP
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_START_APP);
				break;
		}	
	}
	
	if(s_pme_list_screen.otype > PME_OTYPE_NONE){//启动附加功能
		switch(s_pme_list_screen.otype){
			case PME_OTYPE_WAP:
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_START_APP);
				break;
			case PME_OTYPE_CALL:
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_START_CALL);
				break;
			case PME_OTYPE_SMS:
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_START_APP);
				break;
			case PME_OTYPE_APPENTRY:
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_START_APP);
				break;
			case PME_OTYPE_APPLOAD:
				menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_DOWN_LAOD);
				break;
		}
	}
	
	ShowCategory353Screen((U8 *)GetString(STR_GLOBAL_OK), 0,
						  STR_GLOBAL_OK, IMG_GLOBAL_OK,
						  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
						  (S32)nNumofItems, 
						  (U8**)menuStringList,
						  (U16*)gIndexIconsImageList,
						  NULL, 0, 
						  (S32)s_pme_list_screen.opHili, 
						  guiBuffer);

	SetRightSoftkeyFunction(pme_msg_optionscreen_rsk, KEY_EVENT_UP);
	SetLeftSoftkeyFunction(pme_msg_optionscreen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_msg_optionscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * SCR - MSG DETAIL
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: 
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_textscreen_exit(void)
{
	pme_ui_trace((MOD_MMI,"pme_msg_textscreen_exit()"));
	//screen out.
}

/*****************************************************************************
 * FUNCTION: pme_msg_textscreen_lsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_textscreen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_msg_textscreen_lsk()"));

	if(s_pme_list_screen.opNum == 1){//ok
		if(s_pme_list_screen.vonder > 0){
			switch(s_pme_list_screen.stype){
				case PME_STYPE_IM://STR_PME_START_APP
					pme_list_msg_option(PME_MSG_OPTION_IM);
					break;
				case PME_STYPE_EMAIL://STR_PME_START_EMAIL
					pme_list_msg_option(PME_MSG_OPTION_EMAIL);
					break;
				default://STR_PME_START_APP
					pme_list_msg_option(PME_MSG_OPTION_APPENTRY);
					break;
			}
		}else if(s_pme_list_screen.canReply){
			pme_list_msg_option(PME_MSG_OPTION_REPLY);
		}else{//(otype > PME_OTYPE_NONE)
			switch(s_pme_list_screen.otype){
				case PME_OTYPE_WAP:
					pme_list_msg_option(PME_MSG_OPTION_WAP);
					break;
				case PME_OTYPE_CALL:
					pme_list_msg_option(PME_MSG_OPTION_CALL);
					break;
				case PME_OTYPE_SMS:
					pme_list_msg_option(PME_MSG_OPTION_SMS);
					break;
				case PME_OTYPE_APPENTRY:
					pme_list_msg_option(PME_MSG_OPTION_APPENTRY);
					break;
				case PME_OTYPE_APPLOAD:
					pme_list_msg_option(PME_MSG_OPTION_APPLOAD);
					break;
			}
		}
		
	}else if(s_pme_list_screen.opNum > 1){//option
		pme_msg_optionscreen_entry();
	}
	
}

/*****************************************************************************
 * FUNCTION: 
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_textscreen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_msg_textscreen_rsk()"));
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: pme_msg_textscreen_entry
 * DESCRIPTION: show text screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_msg_textscreen_entry(void)
{
	U8* gui_buffer; 
	S32 iBufLength = 0;
	uint16 *txtData;
	uint16 *txtTitle;
	pme_ui_trace((MOD_MMI,"pme_msg_textscreen_entry()"));

	EntryNewScreen(SCR_PME_TEXT_DETAIL, pme_msg_textscreen_exit, pme_msg_textscreen_entry, NULL);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_TEXT_DETAIL);

	iBufLength = pme_list_msg_get_context(&txtData, &txtTitle);
	ShowCategory74Screen(STR_GLOBAL_DETAILS, 0,
							NULL, NULL,
							STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
							(U8*)txtData,
							iBufLength,
							gui_buffer); 

	s_pme_list_screen.opNum = 0;
	s_pme_list_screen.vonder = pme_list_msg_get_type(&s_pme_list_screen.stype, &s_pme_list_screen.otype, &s_pme_list_screen.canReply);
	if(s_pme_list_screen.vonder != MR_FAILED){
		if(s_pme_list_screen.vonder > 0){//登录app
			s_pme_list_screen.opNum++;
		}
		
		if(s_pme_list_screen.canReply){//直接回复
			s_pme_list_screen.opNum++;
		}

		if(s_pme_list_screen.otype > PME_OTYPE_NONE){//启动附加功能
			s_pme_list_screen.opNum++;
		}
	}

	if(s_pme_list_screen.opNum == 1){
		if(s_pme_list_screen.vonder > 0){
			switch(s_pme_list_screen.stype){
				case PME_STYPE_IM:
					ChangeLeftSoftkey(STR_PME_START_APP, IMG_GLOBAL_OK);
					break;
				case PME_STYPE_EMAIL:
					ChangeLeftSoftkey(STR_PME_START_EMAIL, IMG_GLOBAL_OK);
					break;
				default:
					ChangeLeftSoftkey(STR_PME_START_APP, IMG_GLOBAL_OK);
					break;
			}
		}else if(s_pme_list_screen.canReply){
			ChangeLeftSoftkey(STR_PME_REPLY_MSG, IMG_GLOBAL_OK);
		}else{//(otype > PME_OTYPE_NONE)
			switch(s_pme_list_screen.otype){
				case PME_OTYPE_WAP:
					ChangeLeftSoftkey(STR_PME_START_APP, IMG_GLOBAL_OK);
					break;
				case PME_OTYPE_CALL:
					ChangeLeftSoftkey(STR_PME_START_CALL, IMG_GLOBAL_OK);
					break;
				case PME_OTYPE_SMS:
					ChangeLeftSoftkey(STR_PME_START_APP, IMG_GLOBAL_OK);
					break;
				case PME_OTYPE_APPENTRY:
					ChangeLeftSoftkey(STR_PME_START_APP, IMG_GLOBAL_OK);
					break;
				case PME_OTYPE_APPLOAD:
					ChangeLeftSoftkey(STR_PME_DOWN_LAOD, IMG_GLOBAL_OK);
					break;
			}
		}
		
		SetLeftSoftkeyFunction(pme_msg_textscreen_lsk, KEY_EVENT_UP);
		SetKeyHandler(pme_msg_textscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
	}else if(s_pme_list_screen.opNum > 1){
		ChangeLeftSoftkey(STR_GLOBAL_OPTIONS, IMG_GLOBAL_OK);
		
		SetLeftSoftkeyFunction(pme_msg_textscreen_lsk, KEY_EVENT_UP);
		SetKeyHandler(pme_msg_textscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
	}else{
		ChangeLeftSoftkey(NULL, NULL);
	}
	
	SetRightSoftkeyFunction(pme_msg_textscreen_rsk, KEY_EVENT_UP);
}

/*****************************************************************************
 * FUNCTION: pme_msg_textscreen_shown
 * DESCRIPTION: show text screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_msg_textscreen_shown(void)
{
	pme_msg_textscreen_entry();
}

/*****************************************************************************
 * SCR - SUB LIST
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: dsm_apl_optionscreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_optionscreen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_list_optionscreen_hilite(), hilight: %d", hilight));
	s_pme_list_screen.opHili = hilight;
}

/*****************************************************************************
 * FUNCTION: dsm_apl_optionscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_optionscreen_exit(void)
{
     //screen out.
	 pme_ui_trace((MOD_MMI,"pme_list_optionscreen_exit()"));
}

/*****************************************************************************
 * FUNCTION: dsm_apl_popscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_optionscreen_del_msg(void)
{
	pme_ui_trace((MOD_MMI,"pme_list_optionscreen_del_msg()"));
	DeleteScreenIfPresent(SCR_PME_SUB_OPTION);
	GoBackHistory();
	pme_list_sub_option(DAPLN_MSG, DAPLO_DELETE);
}

/*****************************************************************************
 * FUNCTION: dsm_apl_optionscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_optionscreen_lsk(void)
{
	pme_list_option_en option = DAPLO_MAX;

	switch(s_pme_list_screen.opType){
		case DAPLN_NAV:
			if(s_pme_list_screen.opHili == 0){
				option = DAPLO_SELECT;
			}else if(s_pme_list_screen.opHili == 1){
				option = DAPLO_EXIT;
			}
			
			break;
		case DAPLN_MSG:
			if(s_pme_list_screen.opHili == 0){
				option = DAPLO_SELECT;
			}else if(s_pme_list_screen.opHili == 1){
				option = DAPLO_DELETE;
			}else if(s_pme_list_screen.opHili == 2){
				option = DAPLO_EXIT;
			}
			
			break;
		default:
			option = DAPLO_EXIT;
			
			break;
	}

	pme_ui_trace((MOD_MMI,"pme_list_optionscreen_lsk(), %d, %d", s_pme_list_screen.opType, option));
	//if(option == DAPLO_DELETE){
	//	pme_list_optionscreen_del_msg();
	//}else
	{
		if(SCR_PME_SUB_OPTION == GetActiveScreenId()){
			gdi_layer_lock_frame_buffer();
			GoBackHistory();
			gdi_layer_unlock_frame_buffer();
		}
		if(s_pme_list_screen.opType == DAPLN_NAV && option == DAPLO_SELECT){
			s_pme_list_screen.subHili = 0;
		}
		pme_list_sub_option(s_pme_list_screen.opType, option);
		DeleteScreenIfPresent(SCR_PME_SUB_OPTION);
	}
}

/*****************************************************************************
 * FUNCTION: dsm_apl_optionscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_optionscreen_rsk(void)
{
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: dsm_apl_optionscreen_entry
 * DESCRIPTION: start app option
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_optionscreen_entry(void)
{
	U8 *guiBuffer;
	U8 *menuStringList[10] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_list_optionscreen_entry()"));

	EntryNewScreen(SCR_PME_SUB_OPTION, pme_list_optionscreen_exit, pme_list_optionscreen_entry, NULL);
	RegisterHighlightHandler(pme_list_optionscreen_hilite);
	guiBuffer = GetCurrGuiBuffer(SCR_PME_SUB_OPTION);
	if(!guiBuffer){
		s_pme_list_screen.opHili = 0;
	}
	
	switch(s_pme_list_screen.opType){
		case DAPLN_NAV:
			menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_VIEW);
			menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_EXIT);
			
			break;
		case DAPLN_MSG:
			menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_VIEW);
			menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_DELETE);
			//menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_HELP);
			menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_EXIT);
			
			break;		
		default: 
			menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_EXIT);
			break;
	}
	
	ShowCategory353Screen((U8 *)GetString(STR_GLOBAL_OK), 0,
						  STR_GLOBAL_OK, IMG_GLOBAL_OK,
						  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
						  (S32)nNumofItems, 
						  (U8**)menuStringList,
						  (U16*)gIndexIconsImageList,
						  NULL, 0, 
						  (S32)s_pme_list_screen.opHili, 
						  guiBuffer);

	SetRightSoftkeyFunction(pme_list_optionscreen_rsk, KEY_EVENT_UP);
	SetLeftSoftkeyFunction(pme_list_optionscreen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_list_optionscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_free_res
 * DESCRIPTION: free all the screen res
 * PARAMETERS: 
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_free_res(void)
{
	pme_ui_trace((MOD_MMI,"pme_list_screen_free_res()"));
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_exit(void)
{
     //screen out.
	wgui_restore_list_menu_slim_style();
	 pme_ui_trace((MOD_MMI,"pme_list_screen_exit()"));
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_list_screen_lsk()"));
	s_pme_list_screen.opType = pme_list_sub_get_item_type(s_pme_list_screen.subHili);
	pme_list_sub_set_focut_msg(s_pme_list_screen.subHili);
	pme_list_optionscreen_entry();
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_list_screen_rsk()"));
	pme_list_sub_screen_back();
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_ok(void)
{
	pme_ui_trace((MOD_MMI,"pme_list_screen_ok(), subHili: %d", s_pme_list_screen.subHili));
	s_pme_list_screen.opHili = 0;
	s_pme_list_screen.opType = pme_list_sub_get_item_type(s_pme_list_screen.subHili);
	pme_list_sub_set_focut_msg(s_pme_list_screen.subHili);
	pme_list_optionscreen_lsk();
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_del
 * DESCRIPTION: screen been  deleted
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static U8 pme_list_screen_del(void *data)
{
	pme_ui_trace((MOD_MMI,"pme_list_screen_del(), %d", data));
	pme_list_sub_exit();
	pme_list_screen_free_res();
	wgui_restore_list_menu_slim_style();
	return MMI_FALSE;
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_set_sk
 * DESCRIPTION: set soft key handle
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_set_sk(void)
{
	s_pme_list_screen.opType = pme_list_sub_get_item_type(s_pme_list_screen.subHili);
	pme_ui_trace((MOD_MMI,"pme_list_screen_set_sk(), subHili: %d, opType: %d", s_pme_list_screen.subHili, s_pme_list_screen.opType));

	if(pme_list_sub_is_first_page()){
		ChangeRightSoftkey(STR_GLOBAL_EXIT, IMG_GLOBAL_BACK);
	}else{
		ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
	}
	SetRightSoftkeyFunction(pme_list_screen_rsk, KEY_EVENT_UP);
	switch(s_pme_list_screen.opType){
		case DAPLN_NAV:
			ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
			SetLeftSoftkeyFunction(pme_list_screen_ok, KEY_EVENT_UP);
			
			break;
		default: 
			ChangeLeftSoftkey(STR_GLOBAL_OPTIONS, IMG_GLOBAL_OK);
			SetLeftSoftkeyFunction(pme_list_screen_lsk, KEY_EVENT_UP);
			
			break;
	}
	
	SetKeyHandler(pme_list_screen_ok, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_list_screen_show(), hilight: %d", hilight));
	s_pme_list_screen.subHili = hilight;
	pme_list_screen_set_sk();
}

/*****************************************************************************
 * FUNCTION: pme_list_screen_get_list_icon
 * DESCRIPTION: 
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
uint16 pme_list_screen_get_list_icon(int32 isNew)
{
	if(isNew){
		return IMG_PME_LIST_MSG_NEW;
	}else{
		return IMG_PME_LIST_MSG_READ;
	}
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_entry
 * DESCRIPTION: start app list
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_show(int32 refresh)
{
	U8 *guiBuffer;
	U8 *menuStringList[PME_SUB_SCREEN_ITEM_MAX + 1] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_list_screen_show(), refresh: %d", refresh));

	if(refresh){
		gdi_layer_lock_frame_buffer();
		UI_common_screen_pre_exit();
		UI_common_screen_exit();
		gdi_layer_unlock_frame_buffer();
	}
	guiBuffer = GetCurrGuiBuffer(SCR_PME_SUB_LIST);
	RegisterHighlightHandler(pme_list_screen_hilite);
	
	nNumofItems = pme_list_sub_get_items(menuStringList, PME_SUB_SCREEN_ITEM_MAX + 1, hintDataPtrs, pme_list_icons_image_list);	

	wgui_override_list_menu_slim_style(WGUI_LIST_MENU_SLIM_STYLE_DRAW_ICON);
	
	ShowCategory353Screen((U8 *)GetString(STR_PME_SUBSCR), NULL,
						  STR_GLOBAL_OPTIONS, IMG_GLOBAL_OK,
						  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
						  (S32)nNumofItems, 
						  (U8**)menuStringList,
						  (U16*)pme_list_icons_image_list,
						  hintDataPtrs, 
						  0, 
						  (S32)s_pme_list_screen.subHili, 
						  guiBuffer);
	pme_list_screen_set_sk();
}

/*****************************************************************************
 * FUNCTION: dsm_apl_listscreen_entry
 * DESCRIPTION: start app list
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_list_screen_entry(void)
{
	pBOOL isback = IsBackHistory;
	pme_ui_trace((MOD_MMI,"pme_list_screen_entry()"));

	EntryNewScreen(SCR_PME_SUB_LIST, pme_list_screen_exit, pme_list_screen_entry, NULL);
	SetDelScrnIDCallbackHandler(SCR_PME_SUB_LIST, pme_list_screen_del);
	if(!GetCurrGuiBuffer(SCR_PME_SUB_LIST)){
		s_pme_list_screen.subHili = 0;
	}

	if(pme_list_sub_init() || isback){
		pme_list_screen_show(FALSE);
	}else{
		GoBackHistory();
	}
}

/*****************************************************************************
 * FUNCTION: pme_list_screen_distroy
 * DESCRIPTION: distroy screen 
 * PARAMETERS: 
 * RETURNS: void
 *****************************************************************************/
void pme_list_screen_distroy(void)
{
	pme_ui_trace((MOD_MMI,"pme_list_screen_distroy(), %d, %d", GetActiveScreenId(), SCR_PME_SUB_LIST));
	pme_list_sub_exit();
	pme_list_screen_free_res();
	if(GetActiveScreenId() == SCR_PME_SUB_LIST){
		GoBackHistory();
	}else{
		if(IsScreenPresent(SCR_PME_SUB_LIST)){
			DeleteUptoScrID(SCR_PME_SUB_LIST);//del up SCR_DSM_APL_LIST history
			DeleteNHistory(1);//del SCR_DSM_APL_LIST
			GoBackHistory();
		}
	}
	pme_ui_trace((MOD_MMI,"pme_list_screen_distroy(), OUT"));
}

/*****************************************************************************
 * FUNCTION: pme_list_screen_refresh
 * DESCRIPTION: refresh screen 
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_list_screen_refresh(void)
{
	pme_ui_trace((MOD_MMI,"pme_list_screen_refresh()"));
	pme_list_screen_show(TRUE);
}

/*****************************************************************************
 * SCR - STORAGE SETTING
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_set_storagescreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_storagescreen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_set_storagescreen_hilite(), hilight: %d", hilight));
	s_pme_list_screen.setSubHili = hilight;
}

/*****************************************************************************
 * FUNCTION: pme_set_ringscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_storagescreen_exit(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_storagescreen_exit()"));
     //screen out.
}

/*****************************************************************************
 * FUNCTION: pme_set_ringscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_storagescreen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_storagescreen_lsk(), opHili: %d", s_pme_list_screen.setSubHili));
	if(s_pme_list_screen.setSubHili >= 0 && s_pme_list_screen.setSubHili < PME_MAX_MODE){
		pme_set_storage('B' + s_pme_list_screen.setSubHili);
		DisplayPopup((PU8) GetString(STR_GLOBAL_DONE), IMG_GLOBAL_ACTIVATED, 1, ST_NOTIFYDURATION, SUCCESS_TONE);
		DeleteScreenIfPresent(SCR_PME_SETTING_STORAGE);
		/*切换盘符，重新刷新列表*/
		pme_ui_update_list_screen();
		pme_list_storage_space_check();
	}
}

/*****************************************************************************
 * FUNCTION: pme_set_storagescreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_storagescreen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_storagescreen_rsk()"));
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: pme_set_storagescreen_entry
 * DESCRIPTION: mod setting screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_storagescreen_entry(void)
{
	U8 *guiBuffer;
	U8 *menuStringList[10] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_set_storagescreen_entry()"));

	EntryNewScreen(SCR_PME_SETTING_STORAGE, pme_set_storagescreen_exit, pme_set_storagescreen_entry, NULL);
	RegisterHighlightHandler(pme_set_storagescreen_hilite);
	guiBuffer = GetCurrGuiBuffer(SCR_PME_SETTING_STORAGE);
	if(!guiBuffer){
		s_pme_list_screen.setSubHili = ( pme_get_storage() == 'B' ? 0 : 1);
	}

	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_STORAGE_PHONE);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_STORAGE_TCARD);

	ShowCategory109Screen(STR_PME_STORAGE_SET, 0,
							  STR_GLOBAL_OK, IMG_GLOBAL_OK, 
							  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
							  (S32)nNumofItems, (U8**)menuStringList, NULL,
							  (S32)s_pme_list_screen.setSubHili, guiBuffer); 

	SetRightSoftkeyFunction(pme_set_storagescreen_rsk, KEY_EVENT_UP);
	SetLeftSoftkeyFunction(pme_set_storagescreen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_set_storagescreen_lsk, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * SCR - RING SETTING
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_set_ringscreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_ringscreen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_set_ringscreen_hilite(), hilight: %d", hilight));
	s_pme_list_screen.setSubHili = hilight;
}

/*****************************************************************************
 * FUNCTION: pme_set_ringscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_ringscreen_exit(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_ringscreen_exit()"));
     //screen out.
}

/*****************************************************************************
 * FUNCTION: pme_set_ringscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_ringscreen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_ringscreen_lsk(), opHili: %d", s_pme_list_screen.setSubHili));
	if(s_pme_list_screen.setSubHili >= 0 && s_pme_list_screen.setSubHili < PME_MAX_MODE){
		pme_set_ring(s_pme_list_screen.setSubHili);
		DisplayPopup((PU8) GetString(STR_GLOBAL_DONE), IMG_GLOBAL_ACTIVATED, 1, ST_NOTIFYDURATION, SUCCESS_TONE);
		DeleteScreenIfPresent(SCR_PME_SETTING_RING);
	}
}

/*****************************************************************************
 * FUNCTION: pme_set_ringscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_ringscreen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_ringscreen_rsk()"));
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: pme_set_ringscreen_entry
 * DESCRIPTION: mod setting screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_ringscreen_entry(void)
{
	U8 *guiBuffer;
	U8 *menuStringList[10] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_set_modscreen_entry()"));

	EntryNewScreen(SCR_PME_SETTING_RING, pme_set_ringscreen_exit, pme_set_ringscreen_entry, NULL);
	RegisterHighlightHandler(pme_set_ringscreen_hilite);
	guiBuffer = GetCurrGuiBuffer(SCR_PME_SETTING_RING);
	if(!guiBuffer){
		int32 mod = pme_get_ring();
		s_pme_list_screen.setSubHili = mod >= 0 ? mod : 0;
	}

	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_RING_CLOSE);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_RING_OPEN);

	ShowCategory109Screen(STR_PME_RING_SET, 0,
							  STR_GLOBAL_OK, IMG_GLOBAL_OK, 
							  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
							  (S32)nNumofItems, (U8**)menuStringList, NULL,
							  (S32)s_pme_list_screen.setSubHili, guiBuffer); 

	SetRightSoftkeyFunction(pme_set_ringscreen_rsk, KEY_EVENT_UP);
	SetLeftSoftkeyFunction(pme_set_ringscreen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_set_ringscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * SCR - MOD SETTING
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_set_modscreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_modscreen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_set_modscreen_hilite(), hilight: %d", hilight));
	s_pme_list_screen.setSubHili = hilight;
}

/*****************************************************************************
 * FUNCTION: pme_set_modscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_modscreen_exit(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_modscreen_exit()"));
     //screen out.
}

/*****************************************************************************
 * FUNCTION: pme_set_modscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_modscreen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_modscreen_lsk(), opHili: %d", s_pme_list_screen.setSubHili));
	if(s_pme_list_screen.setSubHili >= 0 && s_pme_list_screen.setSubHili < PME_MAX_MODE){
		pme_set_mode(s_pme_list_screen.setSubHili);
		DisplayPopup((PU8) GetString(STR_GLOBAL_DONE), IMG_GLOBAL_ACTIVATED, 1, ST_NOTIFYDURATION, SUCCESS_TONE);
		DeleteScreenIfPresent(SCR_PME_SETTING_MOD);
	}
}

/*****************************************************************************
 * FUNCTION: pme_set_modscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_modscreen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_set_modscreen_rsk()"));
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: pme_set_modscreen_entry
 * DESCRIPTION: mod setting screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_set_modscreen_entry(void)
{
	U8 *guiBuffer;
	U8 *menuStringList[10] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_set_modscreen_entry()"));

	EntryNewScreen(SCR_PME_SETTING_MOD, pme_set_modscreen_exit, pme_set_modscreen_entry, NULL);
	RegisterHighlightHandler(pme_set_modscreen_hilite);
	guiBuffer = GetCurrGuiBuffer(SCR_PME_SETTING_MOD);
	if(!guiBuffer){
		int32 mod = pme_get_mode();
		s_pme_list_screen.setSubHili = mod >= 0 ? mod : PME_CLOSE;
	}

	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_MOD_NORMAL);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_MOD_URGENT);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_MOD_SLEEP);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_MOD_CLOSED);

	ShowCategory109Screen(STR_PME_MOD_SET, 0,
							  STR_GLOBAL_OK, IMG_GLOBAL_OK, 
							  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
							  (S32)nNumofItems, (U8**)menuStringList, NULL,
							  (S32)s_pme_list_screen.setSubHili, guiBuffer); 

	SetRightSoftkeyFunction(pme_set_modscreen_rsk, KEY_EVENT_UP);
	SetLeftSoftkeyFunction(pme_set_modscreen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_set_modscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * SCR -SETTINGS
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_option_settingscreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_option_settingscreen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_option_settingscreen_hilite(), hilight: %d", hilight));
	s_pme_list_screen.setHili = hilight;
}

/*****************************************************************************
 * FUNCTION: pme_option_settingscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_option_settingscreen_exit(void)
{
	pme_ui_trace((MOD_MMI,"pme_option_settingscreen_exit()"));
     //screen out.
}

/*****************************************************************************
 * FUNCTION: pme_option_settingscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_option_settingscreen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_option_settingscreen_lsk(), opHili: %d", s_pme_list_screen.setHili));
	
	if(s_pme_list_screen.setHili == 0){//mod
		pme_set_modscreen_entry();
	}else if(s_pme_list_screen.setHili == 1){//ring
		pme_set_ringscreen_entry();
	}else if(s_pme_list_screen.setHili == 2){//storage
		pme_set_storagescreen_entry();
	}
}

/*****************************************************************************
 * FUNCTION: pme_main_optionscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_option_settingscreen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_option_settingscreen_rsk()"));
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: pme_option_settingscreen_init_hint
 * DESCRIPTION: set hint string
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_option_settingscreen_init_hint(void)
{
	int32 set;
	U16 strId;
	int32 i;

    memset(hintData, 0, MAX_SUB_MENU_HINT_SIZE * 3);
	for(i = 0; i < 3; i++){
		hintDataPtrs[i] = hintData[i];
	}
	i = 0;

	set = pme_get_mode();
	switch(set){
		case PME_NORMAL_MODE:
			strId = STR_PME_MOD_NORMAL;
			break;
		case PME_EMERGENCY_MODE:
			strId = STR_PME_MOD_URGENT;
			break;
		case PME_SLEEP_MODE:
			strId = STR_PME_MOD_SLEEP;
			break;
		default:
		case PME_CLOSE:
			strId = STR_PME_MOD_CLOSED;
			break;
			
	}
    mmi_ucs2cpy((S8*)hintData[i++], (const S8*)GetString(strId));

	set = pme_get_ring();
	if(!set){
		strId = STR_PME_RING_CLOSE;
	}else{
		strId = STR_PME_RING_OPEN;
	}
    mmi_ucs2cpy((S8*)hintData[i++], (const S8*)GetString(strId));

	set = pme_get_storage();
	if(set == 'B'){
		strId = STR_PME_STORAGE_PHONE;
	}else{
		strId = STR_PME_STORAGE_TCARD;
	}
    mmi_ucs2cpy((S8*)hintData[i++], (const S8*)GetString(strId));
}

/*****************************************************************************
 * FUNCTION: pme_option_settingscreen_entry
 * DESCRIPTION: start app main settings option
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_option_settingscreen_entry(void)
{
	U8 *guiBuffer;
	U8 *menuStringList[10] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_option_settingscreen_entry()"));

	EntryNewScreen(SCR_PME_OPTION_SETTING, pme_option_settingscreen_exit, pme_option_settingscreen_entry, NULL);
	RegisterHighlightHandler(pme_option_settingscreen_hilite);
	guiBuffer = GetCurrGuiBuffer(SCR_PME_OPTION_SETTING);
	if(!guiBuffer){
		s_pme_list_screen.setHili = 0;
	}
	
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_MOD_SET);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_RING_SET);
	if(pme_get_storage_num() > 1){
		menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_STORAGE_SET);
	}

	pme_option_settingscreen_init_hint();
	ShowCategory353Screen((U8 *)GetString(STR_PME_SETTING), 0,
						  STR_GLOBAL_OK, IMG_GLOBAL_OK,
						  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
						  (S32)nNumofItems, 
						  (U8**)menuStringList,
						  (U16*)gIndexIconsImageList,
						  (U8**)hintDataPtrs, 
						  0, 
						  (S32)s_pme_list_screen.setHili, 
						  guiBuffer);

	SetRightSoftkeyFunction(pme_option_settingscreen_rsk, KEY_EVENT_UP);
	SetLeftSoftkeyFunction(pme_option_settingscreen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_option_settingscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * SCR - MAIN OPTION
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_delacc_popscreen_exit
 * DESCRIPTION: exit the pop screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_delacc_popscreen_exit(void)
{
	//screen out.
	pme_ui_trace((MOD_MMI,"pme_delacc_popscreen_exit()"));
}

/*****************************************************************************
 * FUNCTION: dsm_apl_popscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_delacc_popscreen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_delacc_popscreen_lsk()"));
	DeleteScreenIfPresent(SCR_PME_MAIN_OPTION);
	GoBackHistory();
	/*del the accont*/
	pme_list_main_delete_account();
}

/*****************************************************************************
 * FUNCTION: pme_delacc_popscreen_entry
 * DESCRIPTION: show prompt screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_delacc_popscreen_entry(void)
{
	U8* gui_buffer; 
	pme_ui_trace((MOD_MMI,"pme_delacc_popscreen_entry()"));

	EntryNewScreen(SCR_PME_POP_DELACC, pme_delacc_popscreen_exit, pme_delacc_popscreen_entry, NULL);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_POP_DELACC);

	ShowCategory165Screen(STR_GLOBAL_OK, IMG_GLOBAL_OK,
							STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
							(UI_string_type)get_string(STR_GLOBAL_DELETE),//temp.
							IMG_GLOBAL_QUESTION,
							gui_buffer);
	SetLeftSoftkeyFunction(pme_delacc_popscreen_lsk, KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_free_res
 * DESCRIPTION: free all the screen res
 * PARAMETERS: 
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_free_res(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_screen_free_res()"));
}

/*****************************************************************************
 * FUNCTION: pme_main_optionscreen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_optionscreen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_main_optionscreen_hilite(), hilight: %d", hilight));
	s_pme_list_screen.opHili = hilight;
}

/*****************************************************************************
 * FUNCTION: pme_main_optionscreen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_optionscreen_exit(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_optionscreen_exit()"));
     //screen out.
}

/*****************************************************************************
 * FUNCTION: pme_main_optionscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_optionscreen_lsk(void)
{
	int8 select = 0;
	int8 del = 1;
	int8 setting = 2;
	int8 notify = 3;
	int8 help = 4;
	pme_ui_trace((MOD_MMI,"pme_main_optionscreen_lsk(), opHili: %d", s_pme_list_screen.opHili));

	if(pme_list_main_get_items(NULL, 0, NULL, NULL) == 0){
		select = -1;
		del = -1;
		setting = 0;
		notify = 1;
		help = 2;
	}
	
	if(s_pme_list_screen.opHili == del){//del
		pme_delacc_popscreen_entry();
	}else{
		if(SCR_PME_MAIN_OPTION == GetActiveScreenId()){
			gdi_layer_lock_frame_buffer();
			GoBackHistory();
			gdi_layer_unlock_frame_buffer();
		}
		
		if(s_pme_list_screen.opHili == select){//select
			pme_list_screen_entry();
		}else if(s_pme_list_screen.opHili == setting){//setting
			pme_option_settingscreen_entry();
		}
		else if(s_pme_list_screen.opHili == notify)
		{
			pme_get_notify_list();
		}
		else if(s_pme_list_screen.opHili == help)
		{
			pme_show_help();
		}
		DeleteScreenIfPresent(SCR_PME_MAIN_OPTION);
	}
}

/*****************************************************************************
 * FUNCTION: pme_main_optionscreen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_optionscreen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_optionscreen_rsk()"));
	GoBackHistory();
}

/*****************************************************************************
 * FUNCTION: pme_main_optionscreen_entry
 * DESCRIPTION: start app main screen option
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_optionscreen_entry(void)
{
	U8 *guiBuffer;
	U8 *menuStringList[10] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_main_optionscreen_entry()"));

	EntryNewScreen(SCR_PME_MAIN_OPTION, pme_main_optionscreen_exit, pme_main_optionscreen_entry, NULL);
	RegisterHighlightHandler(pme_main_optionscreen_hilite);
	
	guiBuffer = GetCurrGuiBuffer(SCR_PME_MAIN_OPTION);
	
	if(!guiBuffer){
		s_pme_list_screen.opHili = 0;
	}

	if(pme_list_main_get_items(NULL, 0, NULL, NULL) > 0){
		menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_SELECT);
		menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_DELETE);
	}

	menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_SETTINGS);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_NOTIFY);
	menuStringList[nNumofItems++] = (U8*)get_string(STR_PME_HELP);
	
	//menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_HELP);
	//menuStringList[nNumofItems++] = (U8*)get_string(STR_GLOBAL_EXIT);

	ShowCategory353Screen((U8 *)GetString(STR_GLOBAL_OPTIONS), 0,
						  STR_GLOBAL_OK, IMG_GLOBAL_OK,
						  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
						  (S32)nNumofItems, 
						  (U8**)menuStringList,
						  (U16*)gIndexIconsImageList,
						  NULL, 0, 
						  (S32)s_pme_list_screen.opHili, 
						  guiBuffer);

	SetRightSoftkeyFunction(pme_main_optionscreen_rsk, KEY_EVENT_UP);
	SetLeftSoftkeyFunction(pme_main_optionscreen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_main_optionscreen_lsk, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * SCR - MAIN LIST
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_main_screen_exit
 * DESCRIPTION: exit the list screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_exit(void)
{
	//screen out.
	wgui_restore_list_menu_slim_style();
	pme_ui_trace((MOD_MMI,"pme_main_screen_exit()"));
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_screen_lsk()"));
	pme_list_main_set_focut_account(s_pme_list_screen.mainHili);
	pme_main_optionscreen_entry();
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_rsk
 * DESCRIPTION: right soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_rsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_screen_rsk()"));
	pme_main_screen_distroy();
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_ok(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_screen_ok()"));
	pme_list_main_set_focut_account(s_pme_list_screen.mainHili);
	s_pme_list_screen.opHili = 0;
	pme_main_optionscreen_lsk();
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_del
 * DESCRIPTION: screen been  deleted
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static U8 pme_main_screen_del(void *data)
{
	pme_ui_trace((MOD_MMI,"pme_main_screen_del(), %d", data));
	pme_list_main_exit();
	pme_main_screen_free_res();
	wgui_restore_list_menu_slim_style();
	return MMI_FALSE;
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_set_sk
 * DESCRIPTION: set soft key handle
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_set_sk(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_screen_set_sk()"));
	ChangeRightSoftkey(STR_GLOBAL_EXIT, IMG_GLOBAL_BACK);
	SetRightSoftkeyFunction(pme_main_screen_rsk, KEY_EVENT_UP);
	ChangeLeftSoftkey(STR_GLOBAL_OPTIONS, IMG_GLOBAL_OK);
	SetLeftSoftkeyFunction(pme_main_screen_lsk, KEY_EVENT_UP);
	SetKeyHandler(pme_main_screen_ok, KEY_ENTER, KEY_EVENT_UP);
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_hilite
 * DESCRIPTION: hilite changed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_hilite(S32 hilight)
{     
	pme_ui_trace((MOD_MMI,"pme_main_screen_hilite(): hilight: %d", hilight));
	s_pme_list_screen.mainHili = hilight;
	pme_main_screen_set_sk();
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_get_list_icon
 * DESCRIPTION: 
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
uint16 pme_main_screen_get_list_icon(int32 haveNew)
{
	if(haveNew){
		return IMG_PME_LIST_ACNT_NEW;
	}else{
		return IMG_PME_LIST_ACNT_READ;
	}
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_entry
 * DESCRIPTION: show app main screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_show(int32 refresh)
{
	U8 *guiBuffer;
	U8 *menuStringList[PME_MAIN_SCREEN_ITEM_MAX + 1] = {0};
	U16 nNumofItems = 0;
	pme_ui_trace((MOD_MMI,"pme_main_screen_show(): refresh: %d", refresh));

	if(refresh){
		gdi_layer_lock_frame_buffer();
		UI_common_screen_pre_exit();
		UI_common_screen_exit();
		gdi_layer_unlock_frame_buffer();
	}
	guiBuffer = GetCurrGuiBuffer(SCR_PME_MAIN_SCREEN);
	RegisterHighlightHandler(pme_main_screen_hilite);
	
	nNumofItems = pme_list_main_get_items(menuStringList, PME_MAIN_SCREEN_ITEM_MAX + 1, hintDataPtrs, pme_list_icons_image_list);

	wgui_override_list_menu_slim_style(WGUI_LIST_MENU_SLIM_STYLE_DRAW_ICON);
	
	ShowCategory353Screen((U8 *)GetString(STR_PME_MAINSCR), 0,
						  STR_GLOBAL_OPTIONS, IMG_GLOBAL_OK,
						  STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
						  (S32)nNumofItems, 
						  (U8**)menuStringList,
						  (U16*)pme_list_icons_image_list,
						  (U8**)hintDataPtrs, 
						  0, 
						  (S32)s_pme_list_screen.mainHili, 
						  guiBuffer);
	pme_main_screen_set_sk();
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_entry
 * DESCRIPTION: start app main screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_main_screen_entry(void)
{
	int32 time, time0 = mr_getTime();
	int32 logo = FALSE;
	pBOOL isback = IsBackHistory;
	pme_ui_trace((MOD_MMI,"pme_main_screen_entry(): isback: %d", IsBackHistory));

	logo = (GetActiveScreenId() == SCR_PME_ENTRY_LOGO);
	EntryNewScreen(SCR_PME_MAIN_SCREEN, pme_main_screen_exit, pme_main_screen_entry, NULL);
	SetDelScrnIDCallbackHandler(SCR_PME_MAIN_SCREEN, pme_main_screen_del);

	/*del SCR_PME_ENTRY_LOGO*/
	gdi_layer_lock_frame_buffer();
	if(IsScreenPresent(SCR_PME_ENTRY_LOGO)){
		DeleteNHistory(1);
	}
	gdi_layer_unlock_frame_buffer();
	
	if(pme_list_main_init() || isback){
		if(logo){
			time = mr_getTime() - time0;
			while(time < PME_MAIN_LOAD_TIME){
				kal_sleep_task(10);//50ms
				time = mr_getTime() - time0;
			}
		}
		pme_main_screen_show(FALSE);
		if(!isback)
			pme_list_storage_space_check();
	}else{
		GoBackHistory();
	}
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_distroy
 * DESCRIPTION: distroy screen 
 * PARAMETERS: 
 * RETURNS: void
 *****************************************************************************/
void pme_main_screen_distroy(void)
{
	//if(!IsScreenPresent(SCR_DSM_APL_APPS)){
		pme_list_main_exit();
	//}

	pme_main_screen_free_res();
	if(GetActiveScreenId() == SCR_PME_MAIN_SCREEN){
		GoBackHistory();
	}else{
		if(IsScreenPresent(SCR_PME_MAIN_SCREEN)){
			DeleteUptoScrID(SCR_PME_MAIN_SCREEN);//del up SCR_PME_MAIN_SCREEN history
			DeleteNHistory(1);//del SCR_PME_MAIN_SCREEN
			GoBackHistory();
		}
	}
}

/*****************************************************************************
 * FUNCTION: pme_main_screen_refresh
 * DESCRIPTION: refresh screen 
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_main_screen_refresh(void)
{
	pme_main_screen_show(TRUE);
}

/*****************************************************************************
 * SCR - MAIN OPTION
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_new_popscreen_distroy
 * DESCRIPTION: distroy screen 
 * PARAMETERS: 
 * RETURNS: void
 *****************************************************************************/
static void pme_new_popscreen_distroy(void)
{
	if(GetActiveScreenId() == SCR_PME_POP_NEWMSG){
		GoBackHistory();
	}else{
		DeleteScreenIfPresent(SCR_PME_POP_NEWMSG);
	}
}

/*****************************************************************************
 * FUNCTION: pme_delacc_popscreen_exit
 * DESCRIPTION: exit the pop screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_new_popscreen_exit(void)
{
	//screen out.
	pme_ui_trace((MOD_MMI,"pme_new_popscreen_exit()"));
}

/*****************************************************************************
 * FUNCTION: dsm_apl_popscreen_lsk
 * DESCRIPTION: left soft key pressed
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_new_popscreen_lsk(void)
{
	pme_ui_trace((MOD_MMI,"pme_new_popscreen_lsk()"));
	
	pme_clear_idle_msg_ind();
	GoBackHistory();
	/*open the new list*/
	pme_main_entry();//temp.
}

/*****************************************************************************
 * FUNCTION: pme_delacc_popscreen_entry
 * DESCRIPTION: show prompt screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_new_popscreen_entry(void)
{
	U8* gui_buffer; 
	pme_ui_trace((MOD_MMI,"pme_new_popscreen_entry()"));

	EntryNewScreen(SCR_PME_POP_NEWMSG, pme_new_popscreen_exit, pme_new_popscreen_entry, NULL);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_POP_NEWMSG);

	ShowCategory165Screen(STR_GLOBAL_OK, IMG_GLOBAL_OK,
							STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
							(UI_string_type)get_string(STR_PME_NEWMSG),//temp.
							IMG_NEW_MESSAGE_NOTIFICATION_MSG,
							gui_buffer);
	SetLeftSoftkeyFunction(pme_new_popscreen_lsk, KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
}

/*****************************************************************************
 * SCR - MAIN OPTION
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_screen_logo
 * DESCRIPTION: logo
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_screen_logo(void)
{
	S32 x, y;
	S32 w = 0;
	S32 h = 0;
#if 0	
	EntryNewScreen(SCR_PME_ENTRY_LOGO, NULL, NULL, NULL);
	/*draw logo*/
	gdi_image_get_dimension((U8*)DSM_LOGO_BMP, &w, &h);
	x = (LCD_WIDTH - w)/2;
	y = (LCD_HEIGHT - h)/2;
	gdi_layer_clear(GDI_COLOR_WHITE);
	gdi_image_draw(x, y, (U8*)DSM_LOGO_BMP);
	gdi_layer_blt_previous(0, 0, LCD_WIDTH - 1, LCD_HEIGHT - 1);
#endif
}

/*****************************************************************************
 * FUNCTION: pme_main_highlight_handler
 * DESCRIPTION: menu highlight handler
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_main_highlight_handler(void)
{
	pme_ui_trace((MOD_MMI,"pme_main_highlight_handler()"));
    SetLeftSoftkeyFunction(pme_main_entry, KEY_EVENT_UP);
	SetKeyHandler(pme_main_entry, KEY_ENTER, KEY_EVENT_UP);
#ifdef __MMI_TOUCH_SCREEN__
    wgui_reset_list_item_selected_callback();
#endif
} 

/*****************************************************************************
 * FUNCTION: pme_ui_play_tone
 * DESCRIPTION: 播放提示音
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
static void pme_ui_play_tone(void)
{
	pme_ui_trace((MOD_MMI,"pme_ui_play_tone(), %d", mdi_audio_is_idle()));

	if(IsBacklightOn()==MMI_FALSE){
		TurnOnBacklight(1);	
	}

#ifdef __IS_10A__
	if(!srv_prof_if_can_ring())
		return;
#else
	if(!mmi_profiles_check_set_mute()){
		return;
	}
#endif

	if(!mdi_audio_is_idle()){
		return;
	}

#ifdef __IS_10A__
	srv_prof_play_tone(SRV_PROF_TONE_SMS, NULL);
#else
	playRequestedTone(SMS_TONE);
#endif
}

/*****************************************************************************
 * FUNCTION: pme_ui_set_status_icon
 * DESCRIPTION: 开关状态栏icon
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_ui_set_status_icon(int8 type, int32 open)
{
	int32 icon_id;
	
	pme_ui_trace((MOD_MMI, "pme_ui_set_status_icon(), %d", open));
	switch(type){
		case PME_STYPE_EMAIL:
			icon_id = STATUS_ICON_PME_EMAIL;
			break;
		case PME_STYPE_IM:
			icon_id = STATUS_ICON_PME_IM;
			break;
		default:
			icon_id = STATUS_ICON_PME_SYS;
			break;
	}

	if(open){
		BlinkStatusIcon(icon_id);
	}else{
		HideStatusIcon(icon_id);
	}
	
	UpdateStatusIcons();
}

/*****************************************************************************
 * FUNCTION: pme_ui_update_list_screen
 * DESCRIPTION: 刷新列表
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_ui_update_list_screen(void)
{
	if(GetActiveScreenId() == SCR_PME_MAIN_SCREEN){
		pme_list_main_init();
		pme_main_screen_show(TRUE);
	}else if(GetActiveScreenId() == SCR_PME_SUB_LIST){
		pme_list_sub_init();
		pme_list_screen_show(TRUE);
	}
}

/*****************************************************************************
 * FUNCTION: pme_ui_is_list_screen_open
 * DESCRIPTION: 列表是否开启
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
int32 pme_ui_is_list_screen_open(void)
{
	if(GetActiveScreenId() == SCR_PME_MAIN_SCREEN
		|| IsScreenPresent(SCR_PME_MAIN_SCREEN)
		){
		return TRUE;
	}

	return FALSE;
}

/*****************************************************************************
 * FUNCTION: pme_ui_new_msg_notify
 * DESCRIPTION: a new msg comming
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_ui_new_msg_notify(int8 type, char* sender)
{
	pme_ui_trace((MOD_MMI,"pme_ui_new_msg_notify()"));

	
	if(pme_ui_is_list_screen_open()){
		/*更新列表*/
		pme_ui_update_list_screen();
	}else{
		/*显示状态图标*/
		//pme_ui_set_status_icon(type, TRUE);

#ifdef PME_NEWS_POP_ANYWHERE
			
#else
		if(g_keylock_context.gKeyPadLockFlag ==0)
		{
			pme_ui_trace((MOD_MMI,"IsOnIdleScreen, %d", g_idle_context.IsOnIdleScreen));
			//if(g_idle_context.IsOnIdleScreen){//idle上，可以弹出pop提示框

			if(GetActiveScreenId() != SCR_PME_POP_NEWMSG)
			{
				pme_new_popscreen_distroy();//temp.
				pme_new_popscreen_entry();
			}
			//}

		}
#endif
	}

	/*铃声提示*/
	if(pme_get_ring()){
		pme_ui_play_tone();
	}
	
}

/*****************************************************************************
 * FUNCTION: pme_ui_intialize
 * DESCRIPTION: menu 开机初始化
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_ui_intialize(void)
{
       extern void mr_pal_register_status_icon_pen_event_hdlr(int16 icon_id, void (* f)(void));
	mr_pal_register_status_icon_pen_event_hdlr(STATUS_ICON_PME_SYS,pme_main_entry);
	mr_pal_register_status_icon_pen_event_hdlr(STATUS_ICON_PME_EMAIL,pme_main_entry);
	mr_pal_register_status_icon_pen_event_hdlr(STATUS_ICON_PME_IM,pme_main_entry);
	SetHiliteHandler(MENU_PME_MAIN, pme_main_highlight_handler);
}

/*****************************************************************************
 * GLOBAL FUNCTION for MTK MODules
 * 
 *****************************************************************************/

/*****************************************************************************
 * FUNCTION: pme_main_entry
 * DESCRIPTION: enter main screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_main_entry(void)
{
	if(pme_port_storage_wr_forbid()){
		mmi_usb_app_unavailable_popup(0);
		return;
	}
	memset(&s_pme_list_screen, 0, sizeof(s_pme_list_screen));
	pme_screen_logo();
	pme_list_init(PME_MAIN_SCREEN_ITEM_MAX, PME_SUB_SCREEN_ITEM_MAX);
	pme_main_screen_entry();
}

/*****************************************************************************
 * FUNCTION: pme_main_setting
 * DESCRIPTION: enter setting screen
 * PARAMETERS:
 * RETURNS: void
 *****************************************************************************/
void pme_main_setting(void)
{
	pme_option_settingscreen_entry();
}

/*void pme_goback_idle_msg_ind(void)
{
	pme_clear_idle_msg_ind();
	GoBackHistory();
}

static void pme_idle_new_msg_power_key_handle(void )
{
	FuncPtr endKeyFunc =NULL;
	pme_clear_idle_msg_ind();
	PowerAndEndKeyHandler();
	endKeyFunc = GetKeyHandler(KEY_END, KEY_EVENT_DOWN);
	if(endKeyFunc)
		endKeyFunc();
	else
		GoBackHistory();
}
*/
void pme_show_new_msg_ind(void)
{
	U8* gui_buffer;
	EntryNewScreen(SCR_PME_POP_NEWMSG, pme_new_popscreen_exit, pme_new_popscreen_entry, NULL);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_POP_NEWMSG);

	ShowCategory165Screen(STR_GLOBAL_OK, IMG_GLOBAL_OK,
							STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
							(UI_string_type)get_string(STR_PME_NEWMSG),//temp.
							IMG_NEW_MESSAGE_NOTIFICATION_MSG,
							gui_buffer);
	
	ClearAllKeyHandler();
	pme_clear_idle_msg_ind();
	//SetKeyHandler(pme_idle_new_msg_power_key_handle,KEY_END, KEY_EVENT_DOWN);
	SetLeftSoftkeyFunction(pme_new_popscreen_lsk, KEY_EVENT_UP);
//	SetRightSoftkeyFunction(pme_goback_idle_msg_ind, KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
}

static void pme_cancel_get_notify_list(void)
{
	pme_ui_trace((MOD_MMI,"pme_cancel_get_notify_list"));
	pme_get_notify_cancel();

	if(IsScreenPresent(SCR_PME_NOTIFY_BASE))
	{
		DeleteUptoScrID(SCR_PME_NOTIFY_BASE);
		DeleteNHistory(1);
	}
	GoBackHistory();
}

static U8 pme_delete_notify_list_cb(void *data)
{
	pme_get_notify_cancel();
	return MMI_FALSE; 
}

static void entry_pme_list_free_wait(void)
{
	U8* gui_buffer;

	EntryNewScreen(SCR_PME_NOTIFY_FREE_WAIT, NULL,entry_pme_list_free_wait,0);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_NOTIFY_FREE_WAIT);
	
	ShowCategory165Screen(0, 0, 0, 0, (UI_string_type)GetString(STR_GLOBAL_PLEASE_WAIT), IMG_GLOBAL_PROGRESS, gui_buffer);
}

static void pme_notify_list_ok(void)
{
	
	if(!pme_notify_list_get_sel_number())
	{
		DisplayPopup(GetString(STR_PME_NOTIFY_NO_SEL), IMG_GLOBAL_FAIL,0, 1000, 0);
		return;
	}
	
	pme_notify_list_free_action();
	entry_pme_list_free_wait();
}

extern uint8 * pme_notify_list_get_hint(int32 index);
extern uint8 * pme_notify_list_get_dispaly_name(int32 index);

U16 pme_notify_list_get_item_hdlr(S32 item_index, UI_string_type str_buff)
{
	uint8 * str = pme_notify_list_get_dispaly_name(item_index);
	
	pme_ui_trace((MOD_MMI,"pme_notify_list_get_item_hdlr item_index=%d,str=%d",item_index,str));
	
	if(!str)
		return FALSE;
	
   	mmi_ucs2cpy((S8*) str_buff, (S8*) str);
	return TRUE;
}

U16 pme_notify_list_get_item_img_hdlr(S32 item_index, U8 state, PU8 *img_buff_p)
{
	pme_ui_trace((MOD_MMI,"pme_notify_list_get_item_img_hdlr item_index=%d",item_index));
	
    *img_buff_p = get_image((MMI_ID_TYPE) ((state) ? CHECKBOX_ON_IMAGE_ID : CHECKBOX_OFF_IMAGE_ID));
    return TRUE;
}

S32 pme_notify_list_get_hint_hdlr(S32 item_index, UI_string_type *hint_array)
{
	uint8 * str = pme_notify_list_get_hint(item_index);
	
	pme_ui_trace((MOD_MMI,"pme_notify_list_get_hint_hdlr item_index=%d,str=%d",item_index,str));
	
	if(!str)
		return 0;
	
   	mmi_ucs2cpy((S8*) hint_array[0], (S8*) str);
	return 1;
}

static void entry_notify_screen(void)
{
	U8* gui_buffer;
	int32 itemcount;
	U8 *state;

	pme_ui_trace((MOD_MMI,"entry_notify_screen"));
	
	EntryNewScreen(SCR_PME_NOTIFY_LIST, NULL,entry_notify_screen,0);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_NOTIFY_LIST);
	
	itemcount = pme_list_get_notify_items(NULL,MAX_SUB_MENUS,NULL,&state);

	SetCheckboxToggleRightSoftkeyFunctions(pme_notify_list_ok,pme_cancel_get_notify_list);

	gdi_layer_lock_frame_buffer();

	if(gui_buffer)
	{
		*((S32 *)gui_buffer) = 0;
	}
	
	ShowCategory187Screen(STR_PME_NOTIFY_LIST,
						       0,
						       itemcount,
						       pme_notify_list_get_item_hdlr,
						       pme_notify_list_get_item_img_hdlr,
						       NULL,
						       pme_notify_list_get_hint_hdlr,
						       (U8*)state,
						       0,
						       NULL,
						       gui_buffer);

	if(itemcount == 0)
	{
		change_softkey(0, 0,MMI_LEFT_SOFTKEY);
		redraw_softkey(MMI_LEFT_SOFTKEY);
#ifdef __MMI_WGUI_CSK_ENABLE__
		change_softkey(0, 0,MMI_CENTER_SOFTKEY);
		redraw_softkey(MMI_CENTER_SOFTKEY);
#endif
	}
	
	gdi_layer_unlock_frame_buffer();
	gui_BLT_double_buffer(0,0,LCD_WIDTH-1,LCD_HEIGHT-1);
	DeleteScreenIfPresent(SCR_PME_NOTIFY_WAIT);
}

static void pme_notify_show_getting_wait(void)
{
	U8* gui_buffer;
	int32 itemcount;	

	pme_ui_trace((MOD_MMI,"pme_notify_show_getting_wait"));
	
	EntryNewScreen(SCR_PME_NOTIFY_WAIT, NULL,pme_notify_show_getting_wait,0);
	gui_buffer = GetCurrGuiBuffer(SCR_PME_NOTIFY_WAIT);		
	ShowCategory165Screen(0, 0, STR_GLOBAL_CANCEL, 0, (UI_string_type)GetString(STR_GLOBAL_PLEASE_WAIT), IMG_GLOBAL_PROGRESS, gui_buffer);
	SetRightSoftkeyFunction(pme_cancel_get_notify_list,KEY_EVENT_UP);
}

void pme_notify_error(int32 ret)
{	
	pme_ui_trace((MOD_MMI,"pme_notify_error"));
	
	if(ret == MR_SUCCESS)
		DisplayPopup(GetString(STR_GLOBAL_DONE), IMG_GLOBAL_SUCCESS,0, 1000, 0);
	else
		DisplayPopup(GetString(STR_GLOBAL_ERROR), IMG_GLOBAL_FAIL,0, 1000, 0);
	DeleteScreenIfPresent(SCR_PME_NOTIFY_WAIT);
	DeleteScreenIfPresent(SCR_PME_NOTIFY_LIST);	
	DeleteScreenIfPresent(SCR_PME_NOTIFY_FREE_WAIT);
	DeleteScreenIfPresent(SCR_PME_NOTIFY_BASE);
}

static void entry_notify_base(void)
{
	EntryNewScreen(SCR_PME_NOTIFY_BASE,NULL, entry_notify_base, 0);
	SetDelScrnIDCallbackHandler(SCR_PME_NOTIFY_BASE, pme_delete_notify_list_cb);
	set_small_screen();
}

int32 pme_get_notify_list(void)
{
	entry_notify_base();
	pme_notify_show_getting_wait();
	
	if(pme_get_notify_start()==0)
		pme_notify_error(MR_FAILED);
}

void pme_port_show_notify_list(void)
{
	entry_notify_screen();
}

void pme_show_help(void)
{
	U8 *gui_buffer;
	U8* str = (U8*)get_string(STR_PME_HELP_INFO);

	EntryNewScreen(SCR_PME_HELP, 0, pme_show_help, 0);
	
	gui_buffer = GetCurrGuiBuffer(SCR_PME_HELP);
	
	ShowCategory74Screen(STR_PME_HELP, 0,STR_GLOBAL_OK, IMG_GLOBAL_OK,NULL, NULL,
									str, mmi_ucs2strlen((S8*)str),gui_buffer); 
	SetLeftSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);
}
#endif

